﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using UserLicense.Applicationes.Command;
using UserModels;
using UserModels.DTO;

namespace UserLicense.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator _mediator;
        public MenuController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 第一级菜单
        /// </summary>
        /// <param name="menuList"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<List<MenuTree>> MenuList(MenuListCommand menuList)
        {
            var id = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            menuList.accountId = Convert.ToInt32(id);
            return _mediator.Send(menuList);
        }

        /// <summary>
        /// 导航菜单
        /// </summary>
        /// <param name="menuTree"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<List<MenuTree>> MenuTree(MenuTreeCommand menuTree)
        {
            return _mediator.Send(menuTree);
        }

        /// <summary>
        /// 添加菜单信息
        /// </summary>
        /// <param name="menuTreeAdd"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<int> MenuAdd(MenuTreeAddCommand menuTreeAdd)
        {
            return _mediator.Send(menuTreeAdd);
        }
    }
}
